<?php
class tixianControl extends skymvc{
	public $sw;
	public $k;
	public function __construct(){
		parent::__construct();	
		$this->k="ymdian";
		$this->sw=" k='".$this->k."' AND shopid=".SHOPID;
	}
	
	public function onDefault(){
		$limit=20;
		$where= $this->sw;
		$url=APPYMDIAN."?m=tixian";
		$start=get('per_page','i');
		$option=array(
			"start"=>$start,
			"limit"=>$limit,
			"order"=>"id DESC",
			"where"=>$where,
		);
		$rscount=true;
		$data=M("tixian")->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,$limit,$url);	
		$this->smarty->assign(array(
			"data"=>$data
		));
		$this->smarty->display("tixian/index.html");
	}
	
	
	public function onApply(){
		$ymdian=M("ymdian")->selectRow("id=".SHOPID);
		$last=M("tixian")->selectRow(array(
			"order"=>"id DESC",
			"where"=>$this->sw,
			"limit"=>1
		));	
		$this->smarty->assign(array(
			"ymdian"=>$ymdian,
			"last"=>$last
		));
		$this->smarty->display("tixian/apply.html");
	}
	
	public function onSave(){
		
		$money=post('money');
		if($money<100){
			$this->goAll("提现金额不能小于100元");
		}
		$ymdian=M("ymdian")->selectRow("id=".SHOPID);
		if($ymdian['balance']<$money){
			$this->goAll("提现余额不足");
		}
		M("kcorder")->begin();
		$data=M("tixian")->postData();
		$data['dateline']=time();
		$data['k']=$this->k;
		$data['shopid']=SHOPID;
		//减少余额
		M("ymdian")->addMoney(array(
					"shopid"=>SHOPID,
					"balance"=>-$money,
					"content"=>"您提现[money]元"
		));		 
		M("tixian")->insert($data);
		M("kcorder")->commit();
		$this->goAll("提现成功，请等待处理",0,0,APPYMDIAN."?m=tixian");
	}
	
}

?>